package com.vincent.kdp.http;


import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 0704 on 2016/9/25.
 */

public class Http {
    private static Retrofit sRetrofit;
    private static ApiService sApiService;

    public static ApiService rx() {
        if (sRetrofit == null) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(Level.BODY);

            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);

            sRetrofit = new Retrofit.Builder()
                    .baseUrl("https://api.douban.com/v2/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(httpClient.build())
                    .build();
        }
        if (sApiService == null) {
            sApiService = sRetrofit.create(ApiService.class);
        }
        return sApiService;
    }
}
